<?php
/*
  先从memcache中查找有无当前用户_id,
  如果在mem中没有，再去数据库中查找
*/
require_once('../include_db.php');

require_once('../constants.php');

// 创建memcache连接
$mem = create_mem_conn();

// 获取请求中的参数
// PARAM_PHONE_NUMBER 定义在constants.php
//$phone_number = $_GET[PARAM_PHONE_NUMBER];
//$phone_number = $_POST[PARAM_PHONE_NUMBER];
$phone_number = str_replace(" ","",$_POST[PARAM_PHONE_NUMBER]);
//$phone_number = "c";
//echo 'phone_number = ' . $phone_number . NEWLINE;

$_id = $mem->get($phone_number);
//echo 'from mem, id = ' . $_id . NEWLINE;
if (!$_id) {
	//$_id = 0;
	// 如果memcache中没有数据，进行数据库查询
	//$mem_stats = $mem->getStats();
	//if ($mem_stats['curr_items'] == 0) {
		$db = new db();
		$sql = "SELECT _id From pTableUserInfo WHERE pPhoneNumber = '" . $phone_number . "' limit 1";
		if ($result = $db->query($sql)) {
			$row = $result->fetch_assoc();
			//echo 'row = ' . $row['_id'] . NEWLINE;
			$_id = $row['_id'] * 10;
			//cho '数据库中找到，插入mem, ' . $_id . ", number=" . $phone_number . NEWLINE;
			$mem->set($phone_number, $_id, false, 0);		
		}
		if (!$row['_id']) {
			$_id = 0;
		} 
	//}
}
echo $_id;

?>